<template>
  <div class="updateInfo">
     <van-nav-bar title="修改个人信息页" fixed placeholder left-arrow  @click-left="onClickLeft"/>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-checkbox-group v-model="result" direction="horizontal" :max="1">
        <span>性别：</span>
        <van-checkbox name="1">男</van-checkbox>
        <van-checkbox name="2">女</van-checkbox>
      </van-checkbox-group>
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
      </van-form>
  </div>
</template>

<script>
import { Dialog } from "vant";
import { updateUserInfoApi } from "@/utils/api";
export default {
  data() {
    return {
      username: "",
      result: []
    };
  },
  methods: {
    onSubmit() {
      updateUserInfoApi({
        token: localStorage.getItem("token"),
        nickName: this.username,
        sex: this.result[0]
      }).then(res => {
        console.log(res);
        Dialog.alert({
          message: res.msg
        }).then(() => {
          // on close
          this.$router.go(-1);
        });
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    }
  }
};
</script>

<style lang="less" scoped>
.updateInfo {
  .van-checkbox-group {
    font-size: 15px;
    padding: 10px;
    background-color: #fff;
    span {
      margin-left: 5px;
    }
  }
}
</style>
